package com.setup.trac.controller;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.setup.trac.dao.DAOService;
import com.setup.trac.pojo.Utenti;
import com.setup.trac.pojo.condition.FindUtenteById;
import com.setup.trac.service.SearchService;

public class ChangeStatoUtenteController extends AbstractController {

	private SearchService searchService;
	private DAOService daoService;
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Utenti u = getSearchService().find(new Utenti[0], new FindUtenteById(new BigDecimal(request.getParameter("idUtente"))), Utenti.class)[0];
		u.setAbilitato(new Boolean(request.getParameter("stato")));
		if(u.getAbilitato()){
			u.setErroreAccesso(new BigDecimal(0));
		}
		getDaoService().update(u);
		
		response.getOutputStream().write("true".getBytes());
		return null;
	}
	public SearchService getSearchService() {
		return searchService;
	}
	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}
	public DAOService getDaoService() {
		return daoService;
	}
	public void setDaoService(DAOService daoService) {
		this.daoService = daoService;
	}

}
